package org.wanho.shop.dao.impl;

import org.wanho.jdbc.JdbcTemplate;
import org.wanho.shop.dao.ProductDao;
import org.wanho.shop.entity.Product;
import org.wanho.shop.mapper.ProductMapper;
import org.wanho.util.RowMapper;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2023-04-26 11:17
 * Description：<描述>
 */
public class ProductDaoImpl implements ProductDao {

    private JdbcTemplate<Product> jt = new JdbcTemplate<>();
    private RowMapper<Product> rm = new ProductMapper();

    @Override
    public List<Product> selectAll() {
        String sql = new StringBuffer()
                .append(" select ")
                .append("   id,name,price ")
                .append(" from ")
                .append("   t_product ")
                .toString();
        return jt.query(sql,rm);
    }

    @Override
    public Product selectById(int productId) {
        String sql = new StringBuffer()
                .append(" select ")
                .append("   id,name,price ")
                .append(" from ")
                .append("   t_product ")
                .append("  where ")
                .append("   id=? ")
                .toString();
        return jt.queryForObject(sql,rm,productId);
    }
}
